<?php
App::uses("String", "Utility");

class RESTController extends AppController {
    // var $helpers = array ('Html','Form');
	// questa riga permette di utilizzare il componente Permission
    var $components = array('Permission');
	
    public function beforeFilter(){
		parent::beforeFilter();
        // don't require logging in for login and logout actions
        $this->Auth->allow('getHelp');
    }
    
    
    public function getHelp($id_helper,$ismodal="") {
    	Controller::loadModel('HelpLang');
    	$this->layout="ajax";
		$this->autorender = false;
		// if ($this->request->is('ajax')) {
			$help = $this->HelpLang->find('first', array(
				'conditions' => array('Help.codice'=>$id_helper, 'Help.pubblicato'=>'1','HelpLang.locale'=>Configure::read("Config.language")),
				'fields' => array('Help.dt_ins', 'HelpLang.*'), //array of field names
				'type' => 'LEFT',
				'recursive' => 1
				));
					
			if($ismodal=="")	
				echo json_encode($help);
			if($ismodal=="modal"){
				if($help)
					echo (html_entity_decode($help["HelpLang"]["testo"])."<br><small>fonte: <a target='_blank' href='".$help["HelpLang"]["link"]."'>".$help["HelpLang"]["link"]."</a></small>");
				else
					echo __("Attenzione, errore nel caricamento dell'help. Contattare l'amministratore.");
			}
		// }	
		exit();	
    }
}
?>